package com.educate.serviceedu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.educate.commonutils.ResultOne;
import com.educate.serviceedu.entity.EduCourse;
import com.educate.serviceedu.entity.EduTeacher;
import com.educate.serviceedu.service.EduCourseService;
import com.educate.serviceedu.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
@CrossOrigin
public class TeacherFrontController {
    @Autowired
    private EduTeacherService eduTeacherService;
    @Autowired
    private EduCourseService eduCourseService;

    //1分页查询讲师的方法
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public ResultOne getTeacherFrontList(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> pageTeacher = new Page<>(page,limit);
        Map<String,Object> map=eduTeacherService.getTeacherFrontList(pageTeacher);
        //返回分页中的所有数据
        return ResultOne.ok().data(map);
    }
    //2讲师详情
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public ResultOne getTeacherFrontInfo(@PathVariable String teacherId){
        //1根据讲师id查询讲师的基本id
        EduTeacher eduTeacher = eduTeacherService.getById(teacherId);
        //2根据讲师id查询所有课程
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = eduCourseService.list(wrapper);
        return ResultOne.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }

}
